package com.tuishan.myapplication.Views.Users;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentActivity;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;

import com.blankj.utilcode.util.LogUtils;
import com.hjq.bar.OnTitleBarListener;
import com.hjq.bar.TitleBar;
import com.tuishan.myapplication.Adapters.UserLogAdapter;
import com.tuishan.myapplication.Custom.LoadingView;
import com.tuishan.myapplication.R;
import com.tuishan.myapplication.ViewModels.UserLogViewModel;

import cn.qqtheme.framework.picker.OptionPicker;

public class UserLogActivity extends FragmentActivity implements OnTitleBarListener,
        View.OnClickListener {
    LoadingView Loading;
    TitleBar titleBar;
    Context mContext;
    RecyclerView Log_recyclerView;
    UserLogAdapter adapter;
    UserLogViewModel viewModel;
    //1登录 2交易 3安全
    String[] TypeList = new String[]{
            "全部", "登录", "交易", "安全"
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_log);
        mContext = this;
        initView();

    }

    private void initView() {
        Loading = new LoadingView(mContext);
        titleBar = findViewById(R.id.titleBar);
        titleBar = findViewById(R.id.titleBar);
        Log_recyclerView = findViewById(R.id.Log_recyclerView);
        titleBar.setOnTitleBarListener(this);
        adapter = new UserLogAdapter();
        viewModel = ViewModelProviders.of(this).get(UserLogViewModel.class);
        viewModel.init(0);
        viewModel.getConvertList().observe(this, concerts -> adapter.submitList(concerts));
        Log_recyclerView.setAdapter(adapter);
        Log_recyclerView.setLayoutManager(new LinearLayoutManager(this));
    }

    //类型选择器
    private void ShowTypePicker() {
        OptionPicker picker = new OptionPicker(this, TypeList);
        picker.setOffset(2);
        picker.setTitleText("选择类型");
        picker.setSelectedIndex(1);
        picker.setTextSize(24);
        picker.setOnOptionPickListener(new OptionPicker.OnOptionPickListener() {
            @Override
            public void onOptionPicked(int index, String item) {
                LogUtils.e("选择类型：" + index);
                viewModel.init(index);
                viewModel.getConvertList().observe((LifecycleOwner) mContext, concerts -> adapter.submitList(concerts));
            }
        });
        picker.show();
    }

    @Override
    public void onClick(View view) {

    }

    @Override
    public void onLeftClick(View v) {
        finish();
    }

    @Override
    public void onTitleClick(View v) {
    }

    @Override
    public void onRightClick(View v) {
        ShowTypePicker();
    }

}
